<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page import="java.util.*" %>



<c:url var="homeURL" value="/index" />
<a href="${homeURL}" class="button-link ui-corner-all ui-state-default" >Back</a>

<c:if  test="${!empty contact.parent}">
	<h2>Parent</h2>
	<c:set var="parent" value="${contact.parent}" scope="request" /> 
	<div class="parent-wrapper">
		<jsp:include page="parent_recurse.jsp" />
	</div>
	<div style="clear:both;"></div>
	
</c:if>
<h2 >Contact</h2>
<c:set var="hasDetail" value="false" />
<c:if  test="${(!empty contact.workPhone) || (!empty contact.cellPhone) || (!empty contact.email) || (!empty contact.altEmail) || (!empty contact.url)}">
	<c:set var="hasDetail" value="true" />
</c:if>

<div class="cmd-tree-item-wrapper ui-corner-all">
	<c:if  test="${!empty contact.tagId}">
		<c:choose>
			<c:when test="${contact.tagId == 1}">
				<div class="cmd-tree-item-section cmd-tree-item-label-red">Agency</div>
			</c:when>
			<c:when test="${contact.tagId == 2}">
				<div class="cmd-tree-item-section cmd-tree-item-label-blue">Rep</div>
			</c:when>
			<c:when test="${contact.tagId == 3}">
				<div class="cmd-tree-item-section cmd-tree-item-label-orange">Job</div>
			</c:when>
			<c:when test="${contact.tagId == 4}">
				<div class="cmd-tree-item-section cmd-tree-item-label-green">Contact</div>
			</c:when>
		</c:choose>
	</c:if>
	
	<div class="cmd-tree-item-section cmd-tree-item-content">
		${contact.lastName}<c:if  test="${!empty contact.firstName}">, ${contact.firstName}</c:if>&nbsp;
	</div>
</div>
<c:if  test="${hasDetail}">
	<br/>
	<div id="detail-table-holder${contact.id}" class="detail-table-holder">
		
		<table id="detail-table${contact.id}" class="detail-table">
		<c:if  test="${!empty contact.workPhone}">
			<tr><td>Work Phone</td><td>${contact.workPhone}</td></tr>
		</c:if>
		<c:if  test="${!empty contact.cellPhone}">
			<tr><td>Cell Phone</td><td>${contact.cellPhone}</td></tr>
		</c:if>
		<c:if  test="${!empty contact.email}">
			<tr><td>Email</td><td>${contact.email}</td></tr>
		</c:if>
		<c:if  test="${!empty contact.altEmail}">
			<tr><td>Alt. Email</td><td>${contact.altEmail}</td></tr>
		</c:if>
		<c:if  test="${!empty contact.url}">
			<tr><td>URL</td><td>${contact.url}</td></tr>
		</c:if>
		</table>
		
	</div>
</c:if>
<c:if  test="${!hasDetail}">
	<p>No Details</p>
</c:if>

<h2>communique</h2>
<form:form method="post" modelAttribute="commForm">
	<s:bind path="*">
		<c:if test="${status.error}">
			<div id="errormessage" class="error">Form has errors</div>
		</c:if>
	</s:bind>
	<form:hidden path="parentContactId"/>
	
	<div class="basic-field-wrapper">
		<form:label path="message">Message</form:label>&nbsp;<form:errors path="message" cssClass="error" /><br/>
		<form:textarea path="message" cols="50" rows="10" />
		<br/><br/>
		<form:label path="created" cssClass="basic-field-labbel">Date Time</form:label>
		<form:input path="created" cssClass="basic-text-field" cssStyle="width:160px;" />
		<br/><br/>
		<form:label path="ranking">Rating</form:label>
		<form:select path="ranking">
			<form:option value="1" label="No Way" />
			<form:option value="2" label="Meh" />
			<form:option  value="3" selected="selected" label="Average" />
			<form:option value="4" label="Good" />
			<form:option value="5" label="Great" />
		</form:select>
		<br/><br/>
		<form:label path="commTypeId">Type</form:label>
		<form:select path="commTypeId">
			<form:option value="1" label="Phone Interview" />
			<form:option value="2" label="In-Person Interview" />
			<form:option value="3" label="Call" />
			<form:option value="4" label="In-Person" />
			<form:option value="5" selected="selected" label="Email" />
		</form:select>
		<br/><br/>
		<c:url var="indexURL" value="/index" />
		<button type="button" onClick="location.href='${indexURL}'">Cancel</button>&nbsp;&nbsp;&nbsp;<button type="submit">Submit</button>
		
		
	</div>
	

</form:form>

<br/>

<c:if  test="${!empty contact.commList}">
	<c:forEach var="comm" items="${contact.commList}">
		<div class="comm-group">
			<div class="comm-wrapper ui-corner-all">
				<div class="comm-info">
				
					<div class="comm-date" style="float:left;"><c:out value="${comm.formatedCreated}" /></div>
					
					<c:choose>
						<c:when test="${comm.commTypeId == 1}">
							<div class="comm-type">Phone Interview</div>
						</c:when>
						<c:when test="${comm.commTypeId == 2}">
							<div class="comm-type">In-Person Interview</div>
						</c:when>
						<c:when test="${comm.commTypeId == 3}">
							<div class="comm-type">Call</div>
						</c:when>
						<c:when test="${comm.commTypeId == 4}">
							<div class="comm-type">In-Person</div>
						</c:when>
						<c:when test="${comm.commTypeId == 5}">
							<div class="comm-type">Email</div>
						</c:when>
					</c:choose>
					
					
					<c:choose>
						<c:when test="${comm.ranking == 1}">
							<div class="comm-ranking" style="background-color:#FF0000;color:black;">No Way</div>
						</c:when>
						<c:when test="${comm.ranking == 2}">
							<div class="comm-ranking" style="background-color:#FFFF66;color:black;">Meh</div>
						</c:when>
						<c:when test="${comm.ranking == 3}">
							<div class="comm-ranking" style="background-color:#EEEEEE;color:black;">Average</div>
						</c:when>
						<c:when test="${comm.ranking == 4}">
							<div class="comm-ranking" style="background-color:#3366FF;">Good</div>
						</c:when>
						<c:when test="${comm.ranking == 5}">
							<div class="comm-ranking" style="background-color:#00FF00;color:black;">Great</div>
						</c:when>
					</c:choose>
					<c:url var="deleteCommURL" value="/comm/delete">
						<c:param name="contactId" value="${contact.id}" />
						<c:param name="commId" value="${comm.id}" />
					</c:url>
					<c:url var="editcommURL" value="/editcomm">
						<c:param name="commId">${comm.id}</c:param>
					</c:url>
					<div class="comm-menu"><a href="${editcommURL}">Edit</a><a href="${deleteCommURL}">Delete</a></div>
				</div>
				<div class="comm-message" style="padding:5px"><c:out value="${comm.message}" /></div>
			</div>
			
		</div>
	</c:forEach>
</c:if>

<script>

$(function() {
	$("button").button();
	$( "#created" ).datetimepicker({ampm: true, dateFormat: 'M d, yy' });
	$( "#e_created" ).datetimepicker({ampm: true, dateFormat: 'M d, yy' });
	$( "#editFormWrapper" ).dialog({ autoOpen: false, modal: false, width: 420 });
});
</script>


